package com.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.entity.Bespeak;
import com.service.BespeakService;

@Controller
public class controller3 {
	@Resource
	private BespeakService bespeakService;
	
	public List<Bespeak> bespeaklist;
	/*功能一: 分页查询
	 * bespeakpage  >>>>>  获取页面信息并分页
	 * 
	 * bespeakpage2  >>>>  上一页
	 * 
	 * bespeakpage3  >>>>  下一页
	 * 
	 * */	
//  获取页面信息并分页
	@RequestMapping(value="bespeakpage",method=RequestMethod.GET)
	public String bespeakpage(Model model){
		bespeaklist = bespeakService.selefen(0);
		
		int ys=0;
		int ys1=1;
		model.addAttribute("bespeaklist", bespeaklist);
		model.addAttribute("ys", ys);
		model.addAttribute("ys1", ys1);
		return "bespeakpage";
	}
//	上一页
	@RequestMapping(value="bespeakpage2",method=RequestMethod.GET)
	public String bespeakpage2(int ys,int ys1,Model model){
		
		bespeaklist = bespeakService.selefen(ys*5);
		
		if(ys==0){
			model.addAttribute("bespeaklist", bespeaklist);
			model.addAttribute("ys", ys);
			model.addAttribute("ys1", ys1);
			return "bespeakpage";
		}
		ys1=ys1-1;
		ys=ys-1;
		model.addAttribute("bespeaklist", bespeaklist);
		model.addAttribute("ys", ys);
		model.addAttribute("ys1", ys1);
		return "bespeakpage";
	}
	
//	下一页
	@RequestMapping(value="bespeakpage3",method=RequestMethod.GET)
	public String bespeakpage3(int ys,int ys1,Model model){
		bespeaklist = bespeakService.selefen(ys1*5);
		
		if(bespeaklist!=null&&!bespeaklist.isEmpty()){
			ys1=ys1+1;
			ys=ys+1;

			model.addAttribute("bespeaklist", bespeaklist);
			model.addAttribute("ys", ys);
			model.addAttribute("ys1", ys1);
			return "bespeakpage";
			
			
		}else{
			model.addAttribute("bespeaklist", bespeaklist);
			model.addAttribute("ys", ys);
			model.addAttribute("ys1", ys1);
			model.addAttribute("ts", "没有了请返回上一页");
			return "bespeakpage";
		}
		
	}
	
//	按条件查询
	@RequestMapping(value="bespeakselect",method=RequestMethod.POST)
	public String bespeakselect(String bname,Model model){
	
		bespeaklist = bespeakService.select(bname);
		
		model.addAttribute("bespeaklist", bespeaklist);
		
		return "bespeakpage";
	}
}

